package com.shqcjd.generalplatformprojectclient.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.generalplatformprojectclient.R;
import com.shqcjd.generalplatformprojectclient.model.pojo.GuidanceMsgBean;
import com.shqcjd.generalplatformprojectclient.util.DateUtil;

import java.util.List;

/**
 * Created by sy on 2018/12/27.
 */

public class GuideMsgAdapter extends BaseQuickAdapter<GuidanceMsgBean,BaseViewHolder>{
    private Context context;
    public GuideMsgAdapter( @Nullable List<GuidanceMsgBean> data, Context context) {
        super(R.layout.item_guide_msg, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, GuidanceMsgBean item) {
        helper.setText(R.id.tv_guide_file_size,item.size)
                .setText(R.id.tv_guide_file_name,item.filename)
                .setText(R.id.tv_guide_file_date, DateUtil.getDateToString(item.uploadTime,"yyyy-MM-dd HH:mm:ss"))
                .addOnClickListener(R.id.tv_guide_file_name);
        if(item.extension.equals(".mp4")){
            helper.getView(R.id.fl_type).setVisibility(View.INVISIBLE);
            helper.getView(R.id.iv_type).setVisibility(View.VISIBLE);
            Glide.with( context )
                    .load(item.url)
                    .thumbnail( 0.1f )
                    .into((ImageView) helper.getView(R.id.iv_type));
        }else if(item.extension.equals(".jpg")||item.extension.equals(".png")){
            helper.getView(R.id.fl_type).setVisibility(View.INVISIBLE);
            helper.getView(R.id.iv_type).setVisibility(View.VISIBLE);
            Glide.with( context )
                    .load(item.url)
                    .into((ImageView) helper.getView(R.id.iv_type));
        }else {
            helper.getView(R.id.fl_type).setVisibility(View.VISIBLE);
            helper.getView(R.id.iv_type).setVisibility(View.INVISIBLE);
        }

    }
}
